package com.dx.common;

import com.dx.common.base.core.LogManager;
import com.jfinal.aop.ClearInterceptor;
import com.jfinal.aop.ClearLayer;
import com.jfinal.core.Controller;
import com.jfinal.ext.render.CaptchaRender;

/**
 * CommonController
 */
public class CommonController extends Controller {
	
	public void index() {
		LogManager.setBiz_id("test.index");
		System.out.println("进入首页了...");
		//render("/common/index.jsp");
		
		//已登录则跳转到登陆成功页面
		System.out.println("user:"+this.getSession().getAttribute("user"));
		this.setAttr("user", this.getSession().getAttribute("user"));
		System.out.println("user:"+this.getAttr("user"));
		render("/WEB-INF/jsp/index.jsp");
//		if(this.getSession().getAttribute("user")!=null)
//			render("/WEB-INF/jsp/index.jsp");
//		else {
//			redirect("/login");
//		}
	}
	
	public void my() {
		//render("/common/index.jsp");
		
		//已登录则跳转到登陆成功页面
		//System.out.println("user:"+this.getSession().getAttribute("user"));
		
		//System.out.println("user:"+this.getAttr("user"));
		//render("/WEB-INF/jsp/index.jsp");
		if(this.getSession().getAttribute("user")!=null){
			this.setAttr("user", this.getSession().getAttribute("user"));
			render("/WEB-INF/jsp/my.jsp");
		}
		else {
			this.getSession().setAttribute("continue_url", "/my");
			redirect("/login");
		}
	}
	
	@ClearInterceptor(ClearLayer.ALL)
	public void random_code() {
		CaptchaRender img = new CaptchaRender("systemRandomCode");
		this.setSessionAttr("systemRandomCode", img.getMd5RandonCode());
	    render(img);
	}
 
}
